package com.chis.netty.http.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * 
 * @Description 
 * @Company zwx
 * @author wlj
 * @version 2019年12月19日
 */
public class HttpsServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline ph = ch.pipeline();
        //添加ssl
//        SSLEngine sslEngine = ServerSslContextFactory.getServerContext().createSSLEngine();
//        sslEngine.setUseClientMode(false);
//        ch.pipeline().addLast(new SslHandler(sslEngine));
        //处理http服务的关键handler
        //一个组合的HttpRequestDecoder和HttpResponseEncoder使得服务器端HTTP实现更容易。
        ph.addLast("codec", new HttpServerCodec());
        ph.addLast("aggregator", new HttpObjectAggregator(10*1024*1024));
        ph.addLast("handler", new HttpServerHandler());// 服务端逻辑处理类

//        ph.addLast("idleStateHandler", new IdleStateHandler(0, 0, 3));
//        EventExecutorGroup businessGroup = new DefaultEventExecutorGroup(2000);
//        ph.addLast(businessGroup, new HttpServerHandler());
    }

}
